home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6238 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: leland.Stanford.EDU!kurri
  2. From: kurri@leland.Stanford.EDU (Ramana Reddy Kurri)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: How to delete array of pointers?
  5. Date: 12 Feb 1996 04:09:27 GMT
  6. Organization: Stanford University
  7. Message-ID: <4fmehn$cum@nntp.Stanford.EDU>
  8. References: <4fgvsu$5q4@eng_ser1.erg.cuhk.hk>
  9. NNTP-Posting-Host: amy6.stanford.edu
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Marty McFly (ywleung@cs.cuhk.hk) wrote:
  13. : If I write the following code in a function:
  14.  
  15. :     int** ptr;
  16. :     ptr = new int*[1000];
  17.  
  18. : Is this code means allocating 1000 integer pointers which is pointed by ptr?
  19.  
  20. YES
  21.  
  22. : And then somehow I assign integer variable to ptr[0], ptr[1], ... and so on.
  23.  
  24.     for(int i=0; i<1000; i++)
  25.        ptr[i] = new int(value); //value is whatever int value you want
  26.  
  27. : So at the end of the function, how can I reclaim just those pointers?  The key
  28. : point is that those integer variable assigned to the pointers should not be 
  29. : deleted.
  30.  
  31. You cannot keep the values pointed by ptr[0], ptr[1], ptr[2] etc.... after deleting 
  32. the memory to them.
  33.  
  34.  
  35. : Regards,
  36. : Marty McFly.
  37.  
  38. Ramana
  39.